<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>机票预订</title>
  <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/ticketBooking.css">
</head>
<body>
<%@ include file="userNavbar.jsp" %>

<div class="booking-container">
  <h2 class="text-2xl font-bold text-gray-800 mb-6 text-center">机票预订</h2>
  <%
    if (session.getAttribute("user") == null) {
  %>
      <p class="text-red-500 text-center">请先登录再进行预订。</p>
  <%
    } else {
      User user = (User) session.getAttribute("user");
      if (request.getMethod().equals("POST")) {
        String fid = request.getParameter("fid");
        String position = request.getParameter("position");
        List<String> input = new ArrayList<>();
        input.add("fid=" + fid);
        input.add("position=" + position);
        boolean result = user.Book_ticket(input);
        if (result) {
  %>
          <p class="text-green-500 text-center">机票预订成功！</p>
  <%
        } else {
  %>
          <p class="text-red-500 text-center">机票预订失败，请检查航班信息或余票情况。</p>
  <%
        }
      }
  %>
  <form action="" method="post">
    <div class="mb-6">
      <label class="block text-gray-700 font-semibold mb-2">航班 ID</label>
      <input type="text" name="fid" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-400" placeholder="请输入航班 ID" required>
    </div>
    <div class="mb-6">
      <label class="block text-gray-700 font-semibold mb-2">舱位</label>
      <input type="text" name="position" class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-400" placeholder="请输入舱位" required>
    </div>
    <button type="submit" class="w-full btn-submit">预订机票</button>
  </form>
  <%
    }
  %>
</div>
</body>
</html>